package com.wcards.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcards.config.R;
import com.wcards.dto.CartsDTO;
import com.wcards.entity.Carts;
import com.wcards.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api("购物车")
@RestController
@Slf4j
@RequestMapping("/carts")
public class CartController {

    @Autowired
    private CartService cartService;
    /*
     * 增加到购物车
     * */

    @ApiOperation("加入到购物车")
    @PostMapping("/creatCart")
    public R<String> creatCart(@RequestBody Carts carts) {
        log.info("逆天了孩子");


        return cartService.addCart(carts);
    }

    /*
     * 购物车删除
     * */
    @ApiOperation("删除购物车")
    @DeleteMapping("/delete")
    public R<String> deleteCart(@RequestParam List<Integer> ids) {
        log.info("删除");
        return cartService.deleteById(ids);
    }

    /*
     * 购物车修改
     * */
    @ApiOperation("修改购物车")
    @PutMapping("/updateCart")
    public R<String> updateCate(@RequestBody Carts carts) {
        log.info("修改购物车");
        return cartService.updateCart(carts);
    }


    /*
     * 查询购物车
     * */
    @ApiOperation("查询购物车")
    @GetMapping("/findCare")
    public R<Page<Carts>> findCate(@RequestBody CartsDTO cartsDTO, Integer pageSize, Integer pageNumber) {
        return cartService.findCates(cartsDTO, pageSize, pageNumber);
    }


}
